// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class SPECIMEN_ORL_O34 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("10 SPM",10)]
  	    [HL7Field(HL7Version.v25, 10, HL7Repeat.False, HL7Required.True,"SPM")]
	    public SPM SPM {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("11 OBX",11)]
  	    [HL7Field(HL7Version.v25, 11, HL7Repeat.True, HL7Required.False,"OBX")]
	    public OBX[] OBX {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("12 SAC",12)]
  	    [HL7Field(HL7Version.v25, 12, HL7Repeat.True, HL7Required.False,"SAC")]
	    public SAC[] SAC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("13 ORDER",13)]
  	    [HL7Field(HL7Version.v25, 13, HL7Repeat.True, HL7Required.False,"ORDER_ORL_O34")]
	    public ORDER_ORL_O34[] ORDER {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			SPM = PopSegmentParseAndCheckRequired<SPM>(availableData, options, "SPM");
			OBX = PopSegmentParseAndCheckRequiredArray<OBX>(availableData, options, "OBX");
			SAC = PopSegmentParseAndCheckRequiredArray<SAC>(availableData, options, "SAC");
			ORDER = ProcessGroupArray<ORDER_ORL_O34>(availableData, options, "ORDER");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isSPM = availableData.StartsWith("SPM", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("SPM", options.Version) || isSPM) {
				return isSPM;
			}
			bool isOBX = availableData.StartsWith("OBX", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("OBX", options.Version) || isOBX) {
				return isOBX;
			}
			bool isSAC = availableData.StartsWith("SAC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("SAC", options.Version) || isSAC) {
				return isSAC;
			}
			ORDER_ORL_O34 testORDER_ORL_O34 = new ORDER_ORL_O34();
			bool grpCCORDER_ORL_O34 = (testORDER_ORL_O34.CanConsume(availableData, options));
			if (IsRequired("ORDER", options.Version) || grpCCORDER_ORL_O34) {
				return grpCCORDER_ORL_O34;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "SPECIMEN";
			}
        }

        static SPECIMEN_ORL_O34() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(SPECIMEN_ORL_O34));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (SPM != null) {
			string segmentValue = SPM.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (OBX != null && OBX.Length > 0) {
			for (int i = 0; i < OBX.Length; i++) {
				string segmentValue = OBX[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (SAC != null && SAC.Length > 0) {
			for (int i = 0; i < SAC.Length; i++) {
				string segmentValue = SAC[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (ORDER != null && ORDER.Length > 0) {
			for (int i = 0; i < ORDER.Length; i++) {
				string segmentValue = ORDER[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

